﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ww.wwf.wwfbll;

namespace ww.form.lis.sam.qc
{
    public partial class QC_VarForm_Item : ww.form.wwf.SysBaseForm
    {
        public QC_VarForm_Item()
        {
            InitializeComponent();
        }

        DataGridViewRow dgr = null;
        string yq = "";//仪器

        public QC_VarForm_Item(string _yq, string _yqmc,DataGridViewRow _dgr)
        {
            InitializeComponent();
            yq = _yq;
            txt_yqmc.Text = _yqmc;
            dgr = _dgr;

        }

        private void QC_VarForm_Item_Load(object sender, EventArgs e)
        {
            if (!object.Equals(null, dgr))
            {
                txt_bh.Text = dgr.Cells["编号"].Value.ToString();
                txt_zwmc.Text = dgr.Cells["中文名称"].Value.ToString();
                txt_ywmc.Text = dgr.Cells["英文名称"].Value.ToString();
                txt_srdm.Text = dgr.Cells["输入代码"].Value.ToString();
                txt_ph.Text = dgr.Cells["批号"].Value.ToString();
                txt_sccj.Text = dgr.Cells["生产厂家"].Value.ToString();
                txt_yqmk.Text = dgr.Cells["仪器模块"].Value.ToString();
                txt_wzbs.Text = dgr.Cells["位置标识"].Value.ToString();
                ck_zzsy.Checked = (bool)dgr.Cells["正在使用"].Value;
                dtp_syrq.Value = Convert.ToDateTime(dgr.Cells["使用日期"].Value);
                dtp_jsrq.Value = Convert.ToDateTime(dgr.Cells["结束日期"].Value);
                txt_bz.Text = dgr.Cells["备注"].Value.ToString();
            }
        }

        private void button保存_Click(object sender, EventArgs e)
        {
            if (txt_bh.Text.Trim() == "")
                txt_bh.Text = WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "select isnull(max(编号),0)+1 from SAM_ZK_ZKP");

            string zzsy="0";
            if (this.ck_zzsy.Checked) zzsy = "1";

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete SAM_ZK_ZKP where 编号='" + this.txt_bh.Text.Trim() + "';");
            strSql.Append("insert into SAM_ZK_ZKP(");
            strSql.Append("编号,中文名称,英文名称,输入代码,批号,生产厂家,仪器,仪器模块,位置标识,正在使用,使用日期,结束日期,备注");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + this.txt_bh.Text.Trim() + "',");
            strSql.Append("'" + this.txt_zwmc.Text.Trim() + "',");
            strSql.Append("'" + this.txt_ywmc.Text.Trim() + "',");
            strSql.Append("'" + this.txt_srdm.Text.Trim() + "',");
            strSql.Append("'" + this.txt_ph.Text.Trim() + "',");
            strSql.Append("'" + this.txt_sccj.Text.Trim() + "',");
            strSql.Append("'" + this.yq + "',");
            strSql.Append("'" + this.txt_yqmk.Text.Trim() + "',");
            strSql.Append("'" + this.txt_wzbs.Text.Trim() + "',");
            strSql.Append("'" + zzsy + "',");
            strSql.Append("'" + dtp_syrq.Value.ToString("yyyy-MM-dd") + "',");
            strSql.Append("'" + dtp_jsrq.Value.ToString("yyyy-MM-dd") + "',");
            strSql.Append("'" + this.txt_bz.Text.Trim() + "'");
            strSql.Append(")");
            WWFInit.wwfRemotingDao.DbExecuteNonQueryBySqlString(WWFInit.strDBConn, strSql.ToString());

            this.DialogResult = DialogResult.OK;
        }

        private void buttonTC_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
